package com.five.admin.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.admin.dao.SystemAdviceMapper;
import com.five.admin.dao.UserMapper;
import com.five.admin.service.SystemAdviceService;
import com.five.entity.SystemAdvice;
import com.five.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统通知表 服务实现类
 * </p>
 *
 * @author star
 * @since 2021-06-16
 */
@Service
public class SystemAdviceServiceImpl extends ServiceImpl<SystemAdviceMapper, SystemAdvice> implements SystemAdviceService {
    @Autowired
    private SystemAdviceMapper systemAdviceMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 发送通知给指定对象
     * @param systemAdvice 消息内容
     * @param userId 用户id
     */
    @Override
    public void addAdvice(SystemAdvice systemAdvice, List userId) {
        for (int i = 0; i < userId.size(); i++) {
            systemAdvice.setUserId(Long.valueOf((String) userId.get(i)));
            systemAdviceMapper.insert(systemAdvice);
        }
    }
    /**
     * 发送全局通知
     * @param systemAdvice 消息内容
     */
    @Override
    public void addAdviceToAll(SystemAdvice systemAdvice) {
        List<User> users = userMapper.selectAllUser();
        for (User user :users
        ) {
            systemAdvice.setUserId(user.getId());
            systemAdviceMapper.insert(systemAdvice);
        }
    }
}
